package com.llkj.qingnianguoxue.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.BookVideoBean;
import com.llkj.qingnianguoxue.bean.BookVideoListBean;
import com.llkj.qingnianguoxue.util.DisplayUtil;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;
import com.llkj.qingnianguoxue.util.StringUtils;

import java.util.List;

/**
 * 订阅大师适配器
 */
public class BookMasterAdapter extends BaseQuickAdapter<BookVideoBean, BaseViewHolder> {

    public BookMasterAdapter(int layoutResId, List<BookVideoBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, BookVideoBean item) {
        ImageView ivHead = baseViewHolder.getView(R.id.iv_head);
        ImageLoadingUtil.loadImgGlideRoundCenterCrop(ivHead, item.getImg());
        RelativeLayout.LayoutParams ivParam = (RelativeLayout.LayoutParams) ivHead.getLayoutParams();
        ivParam.width = DisplayUtil.dip2px(mContext,80)*16/9;
        ivHead.setScaleType(ImageView.ScaleType.CENTER_CROP);

        baseViewHolder.setText(R.id.tv_title,item.getName());
        baseViewHolder.setText(R.id.tv_introduction,item.getAbstractX());
        if(StringUtils.isEmpty(item.getUpdate())){
            baseViewHolder.setText(R.id.tv_update,"0更新");
        }else{
            baseViewHolder.setText(R.id.tv_update,item.getUpdate()+"更新");
        }

        TextView tvCategoryName = baseViewHolder.getView(R.id.tv_category_name);
        tvCategoryName.setText("分类名");

        View lineTop = baseViewHolder.getView(R.id.bottomLine);
        if(baseViewHolder.getLayoutPosition()!=0 /*&& "".equals("")*/){//判断当前分类和上一个分类是否相同，不同则显示
            lineTop.setVisibility(View.VISIBLE);
            tvCategoryName.setVisibility(View.GONE);
        }else{//显示新的分类名
            lineTop.setVisibility(View.GONE);
            tvCategoryName.setVisibility(View.GONE);
        }
    }

}
